package com.five.api.controller;


import com.five.api.service.SystemAdviceService;
import com.five.controller.BaseController;
import com.five.entity.SystemAdvice;
import com.five.entity.User;
import com.five.vo.BaseResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统通知表 前端控制器
 * </p>
 *
 * @author star
 * @since 2021-06-16
 */
@RestController
@CrossOrigin
@RequestMapping("systemAdvice")
@Api(tags = "获取通知接口")
public class SystemAdviceController extends BaseController {

    @Autowired
    private SystemAdviceService systemAdviceService;
    @ResponseBody
    @RequestMapping(value = "getAdvice",method = RequestMethod.POST)
    @ApiOperation("获取用户通知")
    public BaseResultVO getAdvice() {
        //获取用户session
        User dbUser = (User) SecurityUtils.getSubject().getPrincipal();
        //System.out.println("-------user--------" + dbUser);
       // List<SystemAdvice> systemAdviceList = systemAdviceService.selectList(userId);

        List<SystemAdvice> systemAdviceList = systemAdviceService.selectList(dbUser.getId());
        return successResp(systemAdviceList);
    }

    @ResponseBody
    @RequestMapping(value = "getReadState",method = RequestMethod.POST)
    @ApiOperation("是否有未读通知")
    public BaseResultVO getReadState(Long userId) {
        boolean readState = systemAdviceService.getReadState(userId);
        return successRespWithMessage(String.valueOf(readState));
    }

}
